// 
// Decompiled by Procyon v0.5.30
// 

package org.bp.spider.util;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Enumeration;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;

public class PropertiesReader
{
    public static String getValue(final String file_name, final String key) throws MissingResourceException {
        final ResourceBundle res = ResourceBundle.getBundle(file_name);
        final String value = res.getString(key);
        return value.trim();
    }
    
    public static Properties getProperties(String file){
    	Properties pro = new Properties();
    	FileInputStream in;
		try {
			in = new FileInputStream(file);
			pro.load(in);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pro;
    }
    
    public static Properties fillProperties(final String file_name) throws MissingResourceException {
        final Properties properties = new Properties();
        final ResourceBundle res = ResourceBundle.getBundle(file_name);
        final Enumeration<String> en = res.getKeys();
        String key = null;
        String value = null;
        while (en.hasMoreElements()) {
            key = en.nextElement().trim();
            value = res.getString(key);
            properties.setProperty(key, value.trim());
        }
        return properties;
    }
    
    public static void setValue(String file_name, final String key, final String value) {
        try {
            final Properties properties = new Properties();
            final PropertiesReader propertiesReader = new PropertiesReader();
            final String staticPath = propertiesReader.getClass().getClassLoader().getResource("").getPath();
            if (file_name.indexOf(".properties") < 0) {
                file_name += ".properties";
            }
            final String file_name_path = staticPath + file_name;
            final FileInputStream in = new FileInputStream(file_name_path);
            properties.load(in);
            final FileOutputStream fis = new FileOutputStream(file_name_path);
            properties.setProperty(key, value);
            properties.store(fis, file_name);
            in.close();
            fis.close();
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}
